//
//  MainViewController.m
//  Tospur-text
//
//  Created by Tospur_hewei on 15/9/24.
//  Copyright (c) 2015年 Tospur_hewei. All rights reserved.
//

#import "MainViewController.h"
#import <SDCycleScrollView.h>
#import <AFNetworking.h>
#import "BuildDetailTableViewController.h"
#import "GroundGlass.h"
#import "SearchViewController.h"
#import "LeftTableViewController.h"
#import "LeftSlideViewController.h"
#import <UIViewController+MMDrawerController.h>
#define kwidth
@interface MainViewController ()<SDCycleScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) NSArray *imageArray;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UISearchController *searchController;//搜索
@property (nonatomic,strong) LeftSlideViewController *LeftSlideVC;
@property(nonatomic,strong) UISearchBar * seachbar;
@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor cyanColor];
    self.navigationItem.title = @"楼盘";
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 375, 667) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_tableView];
    self.tableView.tableHeaderView = [self cycleScrollView];
    
    GroundGlass *backImage = [[GroundGlass alloc]initWithFrame:[UIScreen mainScreen].bounds imageName:@"楼.jpg" style:UIBlurEffectStyleExtraLight];
    self.tableView.backgroundView = backImage;
    
    UIBarButtonItem *searchButton = [[UIBarButtonItem alloc]initWithTitle:@"搜索" style:UIBarButtonItemStylePlain target:self action:@selector(searchButtonAction)];
    self.navigationItem.rightBarButtonItem = searchButton;
    
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithTitle:@"抽屉" style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction)];
    self.navigationItem.leftBarButtonItem = leftButton;
    
    //LeftTableViewController *leftVC = [[LeftTableViewController alloc] init];
    //self.LeftSlideVC = [[LeftSlideViewController alloc] initWithLeftView:leftVC andMainView:self.view];
}
- (void)leftButtonAction
{
    
//    LeftTableViewController * leftDrawer = [[LeftTableViewController alloc] init];
//    UIViewController * center = [[UIViewController alloc] init];
//    UIViewController * rightDrawer = [[UIViewController alloc] init];
//    
//   // MMDrawerController * drawerController = [[MMDrawerController alloc]
//    //                                         initWithCenterViewController:center
//      //                                       leftDrawerViewController:leftDrawer
//        //                                     rightDrawerViewController:rightDrawer];
//    [self.mm_drawerController  toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
    
}

- (void)searchButtonAction
{
    SearchViewController *searchVC = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:searchVC animated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    if (indexPath.row == 1) {
        cell.textLabel.text = @"楼盘";
        cell.imageView.image = [UIImage imageNamed:@"楼.jpg"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 1) {
        BuildDetailTableViewController *buildVC = [[BuildDetailTableViewController alloc]init];
        [self.navigationController pushViewController:buildVC animated:YES];
    }
}


#pragma mark --- 首页轮播图 ---
- (SDCycleScrollView*)cycleScrollView
{
    self.imageArray = @[[ UIImage imageNamed:@"方向.jpg"],[ UIImage imageNamed:@"风景.jpg"],[ UIImage imageNamed:@"努力.jpg"],[ UIImage imageNamed:@"坚持.jpg"],[ UIImage imageNamed:@"认真.jpg"]];
    
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, 375, 200) imagesGroup:_imageArray];
    
    cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    cycleScrollView.delegate = self;
    [self.view addSubview:cycleScrollView];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
       // cycleScrollView.titlesGroup = _titleArray;
        cycleScrollView.localizationImagesGroup = _imageArray;
        
        cycleScrollView.contentMode = UIViewContentModeTop;
        cycleScrollView.clipsToBounds = YES;
        
        cycleScrollView.layer.shadowColor = [UIColor blackColor].CGColor;
        cycleScrollView.layer.shadowOpacity = 0.6;
        cycleScrollView.layer.shadowRadius = 1.0;
        cycleScrollView.clipsToBounds = NO;
    });
    return cycleScrollView;
}
// 点击图片触发的方法
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
